#include "../include/head.h"
#include "../lib/error.h"


void do_ls(char *dirName)
{
    DIR *pDir;

    struct dirent *pDirent;

    if ((pDir = opendir(dirName)) == NULL) {
        fprintf(stderr,"ls1:cannot open %s\n",dirName);
    }
    else {
        while ((pDirent = readdir(pDir)) != NULL) {
            printf("%s\n",pDirent->d_name);
        }
        closedir(pDir);
    }

}

int main(int argc,char *argv[])
{
    if (argc == 1) {
        do_ls(".");
    }
    else{
        while (--argc) {
            printf("%s:\n",*++argv);
            do_ls(*argv);
        }
    }

    return 0;
}
